<template>
  <el-container>
    <div class="header">
      <div class="title">苏小课直播教学平台</div>
      <div class="user-info">
        <div class="notification">
          <i class="bell-icon">🔔</i>
          <span class="badge">1</span>
        </div>
        <div class="user">您好，{{ userStore.uname }}！</div>
        <div class="actions">
          <a href="#">修改密码</a> |
          <a href="./login.html">退出</a>
        </div>
      </div>
    </div>

    <el-header>
      <div class="breadcrumb-nav">
        <el-breadcrumb separator="/">
          <el-breadcrumb-item @click='navigateTo("teacherHome/home.html")'>首页</el-breadcrumb-item>
          <el-breadcrumb-item>资源库</el-breadcrumb-item>
        </el-breadcrumb>
      </div>
    </el-header>

    <el-main>
      <div class="content-wrapper">
        <div class="tab-menu">
          <span :class="{ active: activeTab === 'courseware' }" @click="activeTab = 'courseware'">课件</span>
          <span :class="{ active: activeTab === 'material' }" @click="activeTab = 'material'">资料</span>
          <div class="underline" :style="underlineStyle"></div>
        </div>
        <div v-if="activeTab === 'courseware'" class="filter-section">
          <el-form :inline="true" class="filter-form">
            <el-form-item label="类型">
              <el-checkbox-group v-model="selectedTypes">
                <el-checkbox label="专业知识"></el-checkbox>
                <el-checkbox label="技能操作"></el-checkbox>
              </el-checkbox-group>
            </el-form-item>
            <el-form-item label="课程">
              <el-checkbox-group v-model="selectedCourses">
                <el-checkbox label="全部"></el-checkbox>
                <el-checkbox label="基础会计"></el-checkbox>
                <el-checkbox label="电算化"></el-checkbox>
                <el-checkbox label="财务法规"></el-checkbox>
                <el-checkbox label="工商管理"></el-checkbox>
              </el-checkbox-group>
            </el-form-item>
          </el-form>
          <div class="search-bar">
            <el-input v-model="searchQuery" placeholder="请输入课件名称、章节或知识点" />
            <el-button type="primary" @click="search">搜索</el-button>
          </div>
          <el-table :data="filteredCourseware" class="courseware-table">
            <el-table-column prop="index" label="序号" width="50"></el-table-column>
            <el-table-column prop="name" label="资料名称"></el-table-column>
            <el-table-column prop="course" label="课程"></el-table-column>
            <el-table-column prop="knowledgePoint" label="知识点"></el-table-column>
            <el-table-column prop="uploader" label="上传人"></el-table-column>
            <el-table-column prop="downloads" label="下载"></el-table-column>
            <el-table-column label="操作">
              <template #default="scope">
                <el-button type="text" @click="handleDownload(scope.row)">下载</el-button>
                <el-button type="text" @click="handleFavorite(scope.row)">收藏</el-button>
              </template>
            </el-table-column>
          </el-table>
          <el-pagination
            background
            layout="total, sizes, prev, pager, next, jumper"
            :total="50"
            :page-sizes="[10, 20, 30, 40]"
            :page-size="10"
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange">
          </el-pagination>
        </div>
        <div v-if="activeTab === 'material'">
          <!-- 资料内容区 -->
          <p>资料内容区</p>
        </div>
      </div>
    </el-main>
  </el-container>
</template>

<script setup>
import { useUserStore } from "../../store/user.js";
let userStore = useUserStore();
userStore.storeInit();

import { ref, computed } from "vue";
import "element-plus/dist/index.css";
import "../../../public/header.css";

const activeTab = ref('courseware');
const selectedTypes = ref([]);
const selectedCourses = ref([]);
const searchQuery = ref('');

const courseware = ref([
  { index: 1, name: "基础会计第一章", course: "基础会计", knowledgePoint: "会计基础", uploader: "陈少平", downloads: "3次" },
  { index: 2, name: "基础会计第二章", course: "基础会计", knowledgePoint: "会计核算", uploader: "李明", downloads: "5次" },
  { index: 3, name: "电算化第一章", course: "电算化", knowledgePoint: "电算化基础", uploader: "王丽", downloads: "2次" },
  { index: 4, name: "财务法规第一章", course: "财务法规", knowledgePoint: "法规基础", uploader: "赵强", downloads: "4次" },
  { index: 5, name: "工商管理第一章", course: "工商管理", knowledgePoint: "管理基础", uploader: "钱芳", downloads: "1次" },
]);

const filteredCourseware = computed(() => {
  return courseware.value.filter(item => {
    const matchesQuery = searchQuery.value === '' || item.name.includes(searchQuery.value) || item.knowledgePoint.includes(searchQuery.value);
    const matchesType = selectedTypes.value.length === 0 || selectedTypes.value.includes(item.course);
    const matchesCourse = selectedCourses.value.length === 0 || selectedCourses.value.includes('全部') || selectedCourses.value.includes(item.course);
    return matchesQuery && matchesType && matchesCourse;
  });
});

const search = () => {
  // 搜索逻辑可以在此添加
};

const handleDownload = (row) => {
  console.log(`Downloading ${row.name}`);
};

const handleFavorite = (row) => {
  console.log(`Adding ${row.name} to favorites`);
};

const handleSizeChange = (size) => {
  console.log(`Changed page size to ${size}`);
};

const handleCurrentChange = (page) => {
  console.log(`Changed to page ${page}`);
};

const underlineStyle = computed(() => {
  return {
    width: activeTab.value === 'courseware' ? '40px' : '30px',
    transform: activeTab.value === 'courseware' ? 'translateX(0)' : 'translateX(60px)'
  };
});

function navigateTo(page) {
  window.location.href = `/src/pages/${page}`;
}
</script>

<style scoped>
#app {
  font-family: Arial, sans-serif;
  background-color: #f5f5f5;
  padding: 20px;
}

.el-header {
  background-color: #fff;
  padding: 10px;
  border-bottom: 1px solid #ddd;
}

.top-nav {
  display: flex;
  justify-content: center;
  margin-bottom: 10px;
}

.breadcrumb-nav {
  padding: 0 20px;
}

.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px;
  background-color: #fff;
  border-bottom: 1px solid #ddd;
}

.header .title {
  font-size: 24px;
  color: #1e90ff;
}

.header .user-info {
  display: flex;
  align-items: center;
}

.header .user-info .notification {
  margin-right: 20px;
  position: relative;
}

.header .user-info .notification .badge {
  position: absolute;
  top: -5px;
  right: -5px;
  background-color: red;
  color: #fff;
  border-radius: 50%;
  padding: 2px 5px;
  font-size: 12px;
}

.header .user-info .user {
  margin-right: 10px;
  color: #333;
}

.header .user-info .actions a {
  margin: 0 5px;
  color: #1e90ff;
  text-decoration: none;
}

.el-main {
  display: flex;
  justify-content: center;
}

.content-wrapper {
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px;
  background-color: #fff;
  border-radius: 8px;
  box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}

.tab-menu {
  display: flex;
  justify-content: start;
  margin-bottom: 20px;
  position: relative;
}

.tab-menu span {
  padding: 10px 20px;
  cursor: pointer;
  font-weight: bold;
}

.tab-menu span.active {
  color: #1e90ff;
}

.tab-menu .underline {
  position: absolute;
  bottom: 0;
  height: 2px;
  background-color: #1e90ff;
  transition: transform 0.3s ease;
}

.filter-section {
  margin-bottom: 20px;
}

.search-bar {
  display: flex;
  align-items: center;
  margin-bottom: 20px;
}

.search-bar .el-input {
  width: 300px;
  margin-right: 10px;
}

.courseware-table {
  margin-bottom: 20px;
}
</style>
